package ru.ifmo.croak.impl.ui.query.team1;

import org.h2.index.Index;
import org.junit.internal.InexactComparisonCriteria;

import javax.swing.*;
import java.awt.event.*;

public class QueryUIForm {

    private JPanel jQueryPanel;
    private JButton jButtonSubscribe;
    private JList jSubscriptionList;
    private JButton editButton;
    private JEditorPane jMessagesEditorPane;
    private JSplitPane jSplitPane;


    public QueryUIForm(final SubscriptionsModel subscriptionsModel) {
        System.err.println(jSubscriptionList);
        System.err.println(jQueryPanel);
        System.err.println(subscriptionsModel);
        jSubscriptionList.setModel(subscriptionsModel.getListModel());

        jSubscriptionList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    int index = jSubscriptionList.locationToIndex(e.getPoint());
                    if (index != -1) {
                        subscriptionsModel.editSubscription(index);
                    }
                }
            }
        });
        editButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int index = jSubscriptionList.getSelectedIndex();
                if (index != -1) {
                    subscriptionsModel.editSubscription(index);
                }
            }
        });
        jSubscriptionList.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
            }
        });
        jButtonSubscribe.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                subscriptionsModel.addSubscription();
            }
        });
        frame = new JFrame("QueryUI");
        frame.setContentPane(jQueryPanel);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
    }

    JFrame frame;

    public JFrame getFrame() {
        return frame;
    }

    public JEditorPane getjMessagesEditorPane() {
        return jMessagesEditorPane;
    }




}
